<?php
class ArticlesModel extends Model
{

    const BASE_PRODUCT = 0;
    const ADDITIONAL_PRODUCT = 1;

    public $rules = array(
        'title' => array('required', 'maxLength' => 100),
        'preview' => array('required', 'maxLength' => 255),
        'image' => array('required', 'file' => 'jpg, png, gif'),
        'alias' => array('required', 'maxLength' => 255),
        'content' => array('required'),
    );
    public $attributes = array();
    public $tableName = 'article';

    public function beforeSave()
    {
        $this->attributes['create_date'] = date('Y-m-d H:i:s');
    }

    public function getArticlesAll()
    {
        return $this->getAll("SELECT * FROM {$this->tableName} ORDER BY create_date");
    }

    public function getArticle($alias)
    {
        return $this->getOne("SELECT * FROM {$this->tableName} WHERE alias=:alias", array(':alias' => $alias));
    }
}